{extend name="layout/iframe" /}

{block name="content"}
<!--<blockquote class="layui-elem-quote quoteBox">
    <h3>个人中心</h3>
</blockquote>-->

<div class="layui-card-body layui-layout-admin" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>账号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="name" value="{$adminInfo.login_name}" lay-verify="required" placeholder="" autocomplete="off" readonly>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>原始密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" id="password" name="password" lay-verify="required" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>新密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" id="newpassword" name="newpassword" lay-verify="required" placeholder="" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="required">*</span>确认密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" id="confirmpassword" name="confirmpassword" lay-verify="required" placeholder="" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item layui-row layui-col-xs12">
            <div class="layui-input-block">
                <div class="layui-footer">
                    <button type="button" class="layui-btn layui-btn-primary close-btn">取消</button>
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="laySave">保存 <i class="layui-icon">&#xe609;</i></button>
                </div>
            </div>
        </div>
    </form>
</div>


<input type="hidden" class="save_url" value="{:url('admin/admin/profile')}">
{/block}

{block name="pagescript"}
<script type="text/javascript">
    layui.use(['form', 'layer'], function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;

        // 表单提交
        form.on("submit(laySave)", function(data){
            var password = $('#password').val();
            var newpassword = $('#newpassword').val();
            var confirmpassword = $('#confirmpassword').val();

            if(password == newpassword){
                layer.msg('新密码不能和原始密码一样！');
                $('#newpassword').focus();
                return false;
            }
            if(newpassword != confirmpassword){
                layer.msg('两次密码不一致！');
                $('#confirmpassword').focus();
                return false;
            }

            submitForm(data);
        });

        /**
         * 表单提交
         */
        function submitForm(data){
            // 弹出loading
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

            var url = $('.save_url').val();

            $.ajax({
                url: url,
                data: data.field,
                type: "post",
                dataType: "json",
                success: function(res){
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    if(res.code == 1){
                        layer.closeAll("iframe");

                        // 退出登录
                        $.ajax({
                            url : "/admin/auth/logout",
                            type : 'get',
                            dataType : 'json',
                        }).done(function(data) {
                            layer.msg('退出登录');
                            parent.window.location.reload();
                        });
                    }
                },
                error:function(data){
                    layer.msg("服务器无响应");
                }
            });
        }
    });
</script>
{/block}